﻿using System;
using System.IO;

namespace SIMA.Generator.Utils
{
    internal sealed class Utility
    {
        private Utility()
        {
        }

        internal static void CreateSubDirectory(string name)
        {
            if (!Directory.Exists(name))
            {
                Directory.CreateDirectory(name);
            }
        }

        internal static void CreateSubDirectory(string name, bool deleteIfExist)
        {
            if (Directory.Exists(name))
            {
                Directory.Delete(name, true);
            }

            Directory.CreateDirectory(name);
        }

        internal static string ConvertString(Column _column)
        {
            switch (_column.Type.ToLower())
            {
                case "binary":
                    return "(byte[])Convert.ToString(";
                case "bigint":
                    return "Convert.ToInt64(";
                case "bit":
                    return "Convert.ToBoolean(";
                case "char":
                    return "Convert.ToString(";
                case "datetime":
                    return "Convert.ToDateTime(";
                case "decimal":
                    return "Convert.ToDecimal(";
                case "float":
                    return "Convert.ToSingle(";
                case "image":
                    return "(byte[])Convert.ToString(";
                case "int":
                    return "Convert.ToInt32(";
                case "money":
                    return "Convert.ToDecimal(";
                case "nchar":
                    return "Convert.ToString(";
                case "ntext":
                    return "Convert.ToString(";
                case "nvarchar":
                    return "Convert.ToString(";
                case "numeric":
                    return "Convert.ToDecimal(";
                case "real":
                    return "Convert.ToDecimal(";
                case "smalldatetime":
                    return "Convert.ToDateTime(";
                case "smallint":
                    return "Convert.ToInt16(";
                case "smallmoney":
                    return "Convert.ToSingle(";
                case "text":
                    return "Convert.ToString(";
                case "timestamp":
                    return "Convert.ToDateTime(";
                case "tinyint":
                    return "Convert.ToByte(";
                case "varbinary":
                    return "(byte[])Convert.ToString(";
                case "varchar":
                    return "Convert.ToString(";
                case "uniqueidentifier":
                    return "Guid";
                default:  // Unknow data type
                    throw (new Exception("Invalid SQL Server data type specified: " + _column.Type));
            }
        }
    }
}
